<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>6.jsonp解决跨域</title>
</head>

<body>
    <button onclick="getStudents()">获取学生数据</button>
    <script type="text/javascript">
        function test(data) {
            console.log(data);
        }
        function getStudents() {
            const script = document.createElement('script')
            script.onload = () => {
                script.remove()
            }
            script.src = 'http://127.0.0.1:8080/teachers?callback=test'
            document.body.appendChild(script)
        }
    </script>

    <!-- <script type="text/javascript">
        function callback(data) {
            console.log('callback 被调用了', data);
        }
        
    </script>
    <script type="text/javascript" src="http://127.0.0.1:8080/teachers"></script> -->
</body>

</html>